<?php 
      require_once('../../../Connections/ocmanmanager.php');
      require_once('../../../Connections/checkuser.php'); 
?>
<?php


$colname_issue = "-1";
if (isset($_GET['id'])) {
$colname_issue = $_GET['id'];
}
echo 'id sa issue-->>'.$colname_issue;
//

mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_issue = sprintf("SELECT * FROM issuetable WHERE id = %s", GetSQLValueString($colname_issue, "int"));
$issue = mysql_query($query_issue, $ocmanmanager) or die(mysql_error());
$row_issue = mysql_fetch_assoc($issue);
$totalRows_issue = mysql_num_rows($issue);
echo 'id issue-->'.$issue_id = $colname_issue;

$colname_issueview = "-1";
if (isset($_GET['id'])) {
  $colname_issueview = $_GET['id'];
}
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_issueview = sprintf("SELECT * FROM issuesstatusview WHERE id = %s", GetSQLValueString($colname_issueview, "int"));
$issueview = mysql_query($query_issueview, $ocmanmanager) or die(mysql_error());
$row_issueview = mysql_fetch_assoc($issueview);
$totalRows_issueview = mysql_num_rows($issueview);

$colname_issuenotes = "-1";
if (isset($_GET['id'])) {
  $colname_issuenotes = $_GET['id'];
}
//not included
mysql_select_db($database_ocmanmanager, $ocmanmanager);
$query_issuenotes = sprintf("SELECT * FROM issuenotes WHERE issueid = %s ORDER BY dateadded ASC", GetSQLValueString($colname_issuenotes, "int"));
$issuenotes = mysql_query($query_issuenotes, $ocmanmanager) or die(mysql_error());
$row_issuenotes = mysql_fetch_assoc($issuenotes);
$totalRows_issuenotes = mysql_num_rows($issuenotes);
//end <<-

mysql_select_db($database_ocmanmanager, $ocmanmanager); //issue notes details
$query_issuenotes = sprintf("SELECT * FROM issuenotes WHERE issueid = %s ORDER BY dateadded ASC", GetSQLValueString($colname_issuenotes, "int"));
$issuenotes = mysql_query($query_issuenotes, $ocmanmanager) or die(mysql_error());
$row_issuenotes = mysql_fetch_assoc($issuenotes);
$totalRows_issuenotes = mysql_num_rows($issuenotes);
?>
<!DOCTYPE html> 
<html>
<head>
<meta charset="utf-8">
<title>Ozcrete Mobile - Projects</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
	<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.css" />
	<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/ui/1.8.22/jquery-ui.min.js"></script>
	<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
    <script type="text/javascript">
    	$(function() {
		      $( ".datepicker" ).datepicker();
	       });
    </script>
</head> 
<body> 
<div id="page" data-role="page" data-theme="b">
	<div data-role="header">
		<h1>Issue</h1>
	</div>
    <div class="ui-grid-a">
			<div class="ui-block-a" style="width:30%;">
			  <ul data-role="listview" data-split-icon="arrow-r" data-theme="c">
			    <li><a href="index.php">Projects</a></li>
			    <li><a href="issues.php">Issues</a></li>
			    <li><a href="orders.php">Orders</a></li>
		      </ul>
</div>
			<div class="ui-block-b" style="width:70%;">
			  <div data-role="content">	
		<ul data-role="listview" data-split-icon="arrow-r" data-theme="c">
       
        <li data-role="list-divider"><?php echo $row_issue['issuetitle']; ?></li>
        
        <li>
        	<strong>ID:</strong><?php echo $row_issueview['id']; ?><br />
        	<strong>Subject:</strong> <?php echo $row_issueview['issuetitle']; ?><br />
        	<strong>Project:</strong> <?php echo $row_issueview['projectname']; ?><br />
        	<strong>Status:</strong> <?php echo $row_issueview['issuestatus']; ?><br />
            <strong>Date Created:</strong> <?php echo $row_issue['datecreated']; ?><br />
            <?php if ($row_issue['issuedescription']!="") { ?>
            <div data-role="collapsible">
            	<h3>Description</h3>
          		<p><?php echo $row_issue['issuedescription']; ?></p>  
          	</div>
            <?php } ?>
            <?php if ($row_issue['notes']!="") { ?>
            <div data-role="collapsible">
            	<h3>Notes</h3>
          		<p><?php echo $row_issue['notes']; ?></p>  
          	</div>
            <?php } ?>
            <form action="#" method="post"> <!--form action for the table--!>
            <div data-role="collapsible">
            	<h3>Note Details</h3>
          		<table id="inotes" summary="This table list issues assigned to individuals" width="99%" style="border: 1px, solid, silver;" style"font-size: 11px; font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif" cellpadding="0" cellspacing="0">
                      <caption>Issues Notes</caption>
                      <thead>
                            <tr>
                              <th scope="col" width="8%">Date:</th>  
                              <th scope="col" width="38%">Notes:</th>  
                              <th scope="col" width="21%">Next Action:</th>  
                              <th scope="col" width="15%">Assigned To:</th>  
                              <th scope="col" width="10%">To be done by:</th>  
                              <th scope="col" width="2%">Important</th>
                              <th scope="col" width="2%">Delete</th>
                            </tr>
                      </thead>
                      <tfoot>
                            <tr>
                              <td colspan="6"></td>
                            </tr>
                      </tfoot>
                      <tbody>
                     	<?php if($totalRows_issuenotes<1){
                     	  echo "<tr><td colspan='7' border='1'>Nothing to display</td></tr>";
                          
                     	}
                         else {
                             do { ?>
                			  <!-- decesion making for delete function --!>
                			         <?php
                                        if($row_issuenotes['deleted']==0){
                                     ?>
                			   <tr>
                                 <td><?php echo $row_issuenotes['dateadded'];?></td><!--I change the input--!>
                                 <td><textarea name="inotes" ><?php echo $row_issuenotes['notetitle'];?></textarea></td>                       
                                 <td><input  type="text" name="iaction[]"  class="iaction"   size="4" /></td>
                                 <td><input  type="text" name="assign[]"  class="iassign"   size="4" /></td>
                                 <td><input  type="text" name="idoneby[ ]"  class="idoneby datepicker" size="4" /></td>
                                 <td><input type="checkbox" class="important" name="important[]" id="important[]" <?php echo ($row_issuenotes['important']==1)? "checked":"";?>/></td>
                                 <td><input type="checkbox" id="checkbox[]" name="checkbox[]" value="<?php $row_issuenotes['id'];?>" <?php echo ($row_issuenotes['deleted']==1)? "checked":"";?>/><?php echo $row_issuenotes['id'];?></td>
                              </tr>
                              <?php } 
                                else {
                                    echo "There".$row_issuenotes['deleted']==1 ."are attributes";
                                }
                              } while ($row_issuenotes = mysql_fetch_assoc($issuenotes)); 
                          }?>
                
               <div style="float: right;margin-right: 5px;" style="display: inline;">  
               <input type="submit" name="delete" id="delete" value="Remove from list"/> 
              
               <!--wala to:--!>           
               <!--<button type="submit" name="delete" id="delete" data-theme="a" value="Delete">Remove from List</button>--!>
               
               </div>
               <div style="float: right;margin-right: 5px;">
               <a href="addnotes.php?id=<?php echo $issue_id;?>" data-role="button" style="float: right;margin-right: 5px;" data-rel="dialog">Add Notes</a>
               </div>
               </tbody>
               </table>
                <br /> 
               <div align="right"><a href="index.html" data-role="button" data-icon="check" style="width: 100px;margin:0 auto;" name="save">Save</a></td></div>   
          	</div>
           </form> <!--end form--!>
                <?php
                           // delete function. 
                           
                            if(isset($_POST['delete'])){
                                
                            for($i=0;$i<$totalRows_issuenotes;$i++){
                                
                                $delete = $_REQUEST['delete'];
                                $checkbox = $_REQUEST['checkbox'];
                                
                                $count = count($_REQUEST['checkbox']);
                                $delete_result_num = isset($checkbox[$i]);
                                
                               
                                //below is the sqlscript to the database.
                                
                                $sql_query = "UPDATE issuenotes SET deleted = '1' WHERE id = $delete_result_num";
                                $result = mysql_query($sql_query);                                
                            }
                        }
                            // check data if important or not.
                            if(isset($_POST['save'])){
                                for($j=0;$j<$totalRows_issuenotes;$j++){
                                    $countimp = count($_REQUEST['checkbox']);
                                    $deleteimp = isset($checkboximp[$j]);
                                    
                                    //issue notes important query
                                    $sql_issuenotes = "UPDATE issutenotes SET important = '1' WHERE id = $deleteimp";
                                    $res = mysql_query($sql_issuenotes);
                                    
                                }
                            }
                         ?>
            
          </li>
        </ul>		
	</div></div>
    
		</div><!-- /grid-a -->
        
	
	<!--div data-role="footer">
		<h4>Ozcrete Pools</h4>
	</div-->
</div>

<!--link to other pages (this is to add notes.)--!>
<div id="secondpage" data-role="page"> 
    <div data-role="header">
        <h1>Issue</h1>
    </div>
        <div data-role="content">
            <p>This the page 2</p>
            <p><a href="#firstpage" data-rel="dialog"><?php require_once "addnotes.php";?></a></p>
        </div>
</div>
<!--end of links--!>
 
</body>
</html>
<?php
mysql_free_result($issue);

mysql_free_result($issueview);

mysql_free_result($issuenotes);
?>
